package com.gs.study.web;

import java.util.concurrent.Future;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.gs.study.service.impl.AsyncServiceImpl;
import com.gs.study.util.BaseController;
import com.gs.study.util.ResultJson;

/** 
 * @author gaoshang 
 * @date 创建时间：2018年5月18日 下午2:18:49 
 * @version 1.0 
 * @parameter  
 * @since  
 * @return  
 */
@RequestMapping(value="/Async")
@Controller
public class AsyncCotroller extends BaseController{
	@Autowired
	private AsyncServiceImpl asyncServiceImpl;
	
	@RequestMapping(value="/startThread")
	public void startThread()throws Exception{
	    	Future<String> fu=asyncServiceImpl.doTaskOne();
	    	Future<String> fu3=asyncServiceImpl.doTaskThree();
	    	Future<String> fu2=asyncServiceImpl.doTaskTwo();
			while(true) {
				if(fu.isDone() && fu2.isDone() && fu3.isDone()) {
					// 三个任务都调用完成，退出循环等待
					break;
				}
				//System.exit(0);
				Thread.sleep(1000);
				System.out.println("sssssssssssssssssss"+Thread.activeCount());
			}
			System.out.println("aaaaaaaaaa");
			ResultJson result=new ResultJson(true);
				printString(result.toJSONString());
	}

}
